﻿/*-------------------------------------------------------------------
* 依懒于miniUI,jQuery,jQuery.action
* 作者：江怀玉
* 用途：用于处理前端的datagrid/treegrid通用功能操作事件方法
* 
* 
* 
---------------------------------------------------------------------*/
/* 用于判断是执Sql取数，还是后台专用取数 */
var const_get_action = "";
if (typeof (const_action) != "undefined") {
    //alert(const_action);
    const_get_action = const_action;
}
function onCloseClick(e) {
    var obj = e.sender;
    obj.setText("");
    obj.setValue("");
}

var fnGetSelectedRow = function () {
    var row = grid.getSelected();
    return row;
}

var fnGetSelectedRows = function () {
    var rows = grid.getSelecteds();
    return rows;
}
///新增
var fnAdd = function () {
    if (typeof (fnCustomAdd) != "undefined") {
        fnCustomAdd();
        return;
    }
    mini.open({
        url: "/ExtendPage/editview/DefineEditForm.aspx?formcode=" + getPar("formcode") + "&entity=" + const_EditEntity + "&functionid=" + const_functionId + "&id=",
        title: "新增" + const_PageTitle, width: _openWindowWidth, height: _openWindowHeight,
        onload: function () {
            //var iframe = this.getIFrameEl();
            //var data = { action: "new" };
            //iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}


//
var fnEdit = function () {
    if (typeof (fnCustomEdit) != "undefined") {
        fnCustomEdit();
        return;
    }
    var row = fnGetSelectedRow();
    //debugger
    if (row) {
        mini.open({
            url: "/ExtendPage/editview/DefineEditForm.aspx?formcode=" + getPar("formcode") + "&view_entity=" + const_ViewEntity + "&entity=" + const_EditEntity + "&functionid=" + const_functionId + "&id=" + row[const_entityID],
            title: "编辑" + const_PageTitle, width: _openWindowWidth, height: _openWindowHeight,
            onload: function () {
                //var iframe = this.getIFrameEl();
                //var data = { action: "edit", id: row.id };
                //iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid.reload();

            }
        });

    } else {
        alert("请选中一条记录");
    }
}

///-------------------------------------------
///快速搜索
///-------------------------------------------
var commCondition = "";//zengtongchun 2015-07-17 拿到条件
var fnQuciklyQuery = function (flag) {
    if (typeof (flag) == "undefined") {
        if (typeof (fnCustomQuciklyQuery) == "function") {
            fnCustomQuciklyQuery();
            return;
        }
    }
    if (const_QueryField == undefined || const_QueryField == "") {
        return;
    }

    var _fields = const_QueryField.split(",");
    var _keyword = document.getElementById("QueryContext").value;
    _keyword = _keyword.trim();
    //var _keys = _keyword.trim().split(" ");

    if (_keyword == "") {
        //alert(_condition);
        _condition = "";
        //const_CustomCondition
        //const_Condition

        /* 江怀玉
        var _const_CustomCondition = const_CustomCondition == undefined || const_CustomCondition == "" ? "1=1" : const_CustomCondition;
        var _const_Condition = const_Condition == undefined || const_Condition == "" ? "1=1" : const_Condition;
        var _condition = fnGetQuciklyQueryCondition(0);
        if (this.location.toString().indexOf("tree_master_detail.aspx") > 0) {
            _condition = fnGetQuciklyQueryCondition(1);
        }
        _condition = _condition == "" ? _const_CustomCondition : "(" + _const_CustomCondition + ") and (" + _condition + ")";
        _condition = _condition == "" ? _const_Condition : "(" + _const_Condition + ") and (" + _condition + ")";
        grid.setUrl("../data/jsondata.aspx?action=" + const_get_action + "&functionid=" + const_functionId + "&entity=" + const_entityName + "&condition=" + encodeURI(_condition) + "&order=" + const_Order + "&datagrid=true");
        grid.load();//{ condition:_condition});//mini.encode(_condition)
        return;*/

        var _const_CustomCondition = const_CustomCondition == undefined || const_CustomCondition == "" ? "1=1" : const_CustomCondition;
        var _const_Condition = const_Condition == undefined || const_Condition == "" ? "1=1" : const_Condition;
        var _condition = fnGetQuciklyQueryCondition(0);
        if (this.location.toString().indexOf("tree_master_detail.aspx") > 0) {
            if (const_TreeCustomCondition == "")
            {
                return;
            }
            _condition = const_TreeCustomCondition == "" ? _condition : const_TreeCustomCondition + " and " + (_condition == "" ? "1=1" : _condition);

        }
        _condition = _condition == "" ? _const_CustomCondition : "(" + _const_CustomCondition + ") and (" + _condition + ")";
        _condition = _condition == "" ? _const_Condition : "(" + _const_Condition + ") and (" + _condition + ")";
        grid.setUrl("../data/jsondata.aspx?action=" + const_get_action + "&functionid=" + const_functionId + "&entity=" + const_entityName + "&condition=" + encodeURI(_condition) + "&order=" + const_Order + "&datagrid=true");
        grid.load();//{ condition:_condition});//mini.encode(_condition)
        return;
    }
    var _condition = fnGetQuciklyQueryCondition(0);
    if (this.location.toString().indexOf("tree_master_detail.aspx") > 0)
    {
        _condition = const_TreeCustomCondition == "" ? _condition : const_TreeCustomCondition + " and " + _condition;
    }
    
    grid.setUrl("../data/jsondata.aspx?action=" + const_get_action + "&functionid=" + const_functionId + "&entity=" + const_entityName + "&condition=" + encodeURI(_condition) + "&order=" + const_Order + "&datagrid=true");
    grid.load();//{ condition:_condition});//mini.encode(_condition)
}


/*
para:onlyPageCondition = 1 //仅限于页面表单所呈现的条件
     onlyPageCondition = 0 //包含页面URL所定义的过滤条件 
*/
var fnGetQuciklyQueryCondition = function (onlyPageCondition) {
    var flag = typeof (onlyPageCondition) == "undefined" ? 0 : onlyPageCondition;
    var _chk = document.getElementById("checkAndOr").checked;
    //alert(_chk);
    var _opr = _chk ? " and " : " or ";
    //alert(_opr);

    var queryFileds = "";
    if (typeof (const_QueryFieldsText) != "undefined" && const_QueryFieldsText != "" && $("#QuerySelectItem").val() != "")//
    {
        queryFileds = $("#QuerySelectItem").val();
    } else {
        queryFileds = const_QueryField;
    }

    var _fields = queryFileds.split(",");
    var _keyword = document.getElementById("QueryContext").value;
    var _condition = "";
    if (_keyword == "") {
        return _condition;
    }
    _keyword = _keyword.trim();
    var _keys = _keyword.trim().split(" ");

    for (n = 0; n < _keys.length; n++) {
        if (_keys[n] == "") {
            continue;
        }
        if (n == 0) {
            _condition = " ( ";
        }
        else {
            _condition = _condition + _opr + " ( ";
        }
        for (i = 0; i < _fields.length; i++) {
            if (i == 0) {
                _condition = _condition + " (" + _fields[i] + " like '%" + _keys[n] + "%')  ";
            }
            else {
                _condition = _condition + " or (" + _fields[i] + " like '%" + _keys[n] + "%')  ";
            }
        }
        _condition = _condition + " )";
    }

    if (flag == 1) {
        if (const_CustomCondition != null && const_CustomCondition != undefined && const_CustomCondition != "") {
            _condition = _condition == "" ? const_CustomCondition : "(" + const_CustomCondition + ") and (" + _condition + ")";
        }

        if (const_Condition != null && const_Condition != undefined && const_Condition != "") {
            _condition = _condition == "" ? const_Condition : "(" + const_Condition + ") and (" + _condition + ")";
        }

        if (const_TreeCustomCondition != null && const_TreeCustomCondition != undefined && const_TreeCustomCondition != "") {
            _condition = _condition == "" ? const_TreeCustomCondition : "(" + const_TreeCustomCondition + ") and (" + _condition + ")";
        }
    }
    return _condition;
}


/***-----------------------------通用查询功能-------------------------***/
function showQuery() {
    grid.clearSort();
    $("#datagrid1").height($(document).height() - $("#QueryItem").height() - 37);
    $("#QueryItem").show(1000);
}

function fnCloseQuery() {
    grid.clearSort();
    $("#datagrid1").height($(document).height() - 37);
    $("#QueryItem").hide(1000);
}

function fnEmptyQuery() {
    var items = $("#QueryItem").find("input");
    $.each(items, function (index) {
        $(items[index]).val("");
    }
   );
}
/*-----------------------------/

------------------------------*/
function fnHightLevelQuery() {
    fnQueryRec("QueryItem");
}


//获取组织结构id addzhongxx 2016-04-08
function GetDeptOrdId(orgId) {
    var result = "";
    $.ajax({
        url: "/WharfCostVerify/GetDepartmentsIds",
        type: "get",
        async: false,
        data: { orgId: orgId },
        cache: false,
        success: function (text) {
            result = text;
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        }
    });
    return result;
}

function fnGetCondition(id) {
    var _linkchar = "and";
    //$("#QueryItem").hide(1000);
    var condition = " 1=1 ";
    var items = $("#" + id).find("div[id^=query_item_]");

    var form = new mini.Form("#QueryItem");
    var _data = form.getData();
    $.each(items, function (index) {
        var item = items[index];
        var eq = $(item).find("select").val();
        var _field = $(item).attr("id").replace("query_item_", "");
       
        var ctrls = $(item).find("input[class*=mini]");//表示样式含有mini信息的

        var _value = _data[_field] == undefined ? $(ctrls[0]).val() : _data[_field];// $(ctrls[0]).val();
        //if()
        if (_value.toString().indexOf("GMT") > 0 || _value.toString().indexOf("UTC") > 0) {
            _value = mini.formatDate(_value, "yyyy-MM-dd H:mm:ss");

        }
        
        var falg = false;

        if ($(item).find("span[class*=treeselect]").length > 0 || $(item).find("span[class*=combobox]").length > 0 || $(item).find("span[class*=textbox]").length > 0) {
            //if ($(item).find("span[class*=combobox]").length > 0) {
            if ((_field == "wharf_name" || _field == "dept_id" || _field == "bill_name" || _field == "ship_agent_name" || _field == "apply_no" || _field == "container_no" || _field == "payee_status_names" || _field == "org_id" || _field == "transport_name" || _field == "declare_id" || _field == "transport_way" || _field == "transport_id") && _value != "") {
                var array = _value.split(',');
                var _valueData = "";
                for (var i = 0; i < array.length; i++) {
                    _valueData += "'" + array[i] + "'" + ",";
                }
                _value = _valueData.substring(0, _valueData.length - 1);
                falg = true;    
            }
            //if (_field == "org_id" && _value != "") {
            //    _value = "select id from ufn_get_dept_tree_code('" + _value + "')";
            //    falg = true;
            //}
            if (_field == "org_pathid" && _value != "") {
                _value = GetDeptOrdId(_value);
                falg = true;
            }

        }
            //    //if(($(ctrls[0]).attr("class").indexOf("combobox") > 0) )
            //    //{
            //    //}
        else {
            if ($(ctrls[0]).attr("class").indexOf("check") > 0) {
                _value = $(ctrls[0]).attr('checked') == "checked" ? "1" : "0";
                //_value = _value == "on" ? "1" : "0";
            }
        }
        var c = "";
        if (_value != "") {
            if (ctrls.length < 2) {
                if (falg == true) {
                    if (eq.indexOf("not like") > -1) {
                        c = _field + " not in (" + _value + " )";
                    } else {
                        c = _field + " in (" + _value + " )";
                    }
                } else {

                    if (eq.indexOf("like") > -1) {
                        c = _field + " " + eq + " '%" + _value + "%' ";
                    } else {
                        c = _field + " " + eq + " '" + _value + "' ";
                    }
                }
            } else {
                _value2 = $(ctrls[1]).val();

                if (ctrls[0].className != "mini-textbox-input" && _value2 != "") {
                    _value2 = _value2 + " 23:59:59"; //add by 钟星星
                    _value2 = "'" + _value2 + "'";
                    _value = "'" + _value + "'";
                } else {
                    if (_field == "cabin_nodata" && _value != "") {//现金编号费==》流水号日期
                        _value2 = "'" + _value2 + "'";
                        _value = "'" + _value + "'";
                    } else {
                        _value2 = _value2;
                        _value = _value;
                    }
                }
                if (_value2 != "") {   //时间控件
                    c = _field + " between " + _value + "  and  " + _value2 + " ";
                } else {
                    c = _field + " >=  '" + _value + "' ";
                }
            }
            if (c != "") {
                condition = condition == "" ? c : condition + " " + _linkchar + " " + c;
            }
        }
    });
  
    //alert(condition);
    //return;
    var _condition = condition;
    //var const_CustomCondition = const_CustomCondition == "" ? "1=1" : const_CustomCondition;
    //var const_Condition = const_Condition == "" ? "1=1" : const_Condition;
    if (const_CustomCondition != null && const_CustomCondition != undefined && const_CustomCondition != "") {
        _condition = _condition == "" ? const_CustomCondition : "(" + const_CustomCondition + ") and (" + _condition + ")";
    }
    if (const_Condition != null && const_Condition != undefined && const_Condition != "") {
        _condition = _condition == "" ? const_Condition : "(" + const_Condition + ") and (" + _condition + ")";
    }

    if (const_TreeCustomCondition != null && const_TreeCustomCondition != undefined && const_TreeCustomCondition != "") {
        _condition = _condition == "" ? const_TreeCustomCondition : "(" + const_TreeCustomCondition + ") and (" + _condition + ")";
    }
    return _condition;
}

function fnQueryRec(id) {
    if (typeof (fnCustomQueryRec) == "function") {
        fnCustomQueryRec(id);
        return;
    }
    var _condition = fnGetCondition(id);
    //condition = _condition;
    //commCondition = condition;//zengtongchun 
    //alert( encodeURI(condition));
   
    grid.setUrl("../data/jsondata.aspx?action=" + const_get_action + "&functionid=" + const_functionId + "&totalfields=" + getPar("totalfields") + "&entity=" + const_entityName + "&condition=" + encodeURI(_condition) + "&order=" + const_Order + "&datagrid=true");
    grid.load();
}

var fnCommonQuery = function (condition, function_id) {
    //alert( encodeURI(condition));
    var functionid = typeof (function_id) == "undefined" ? "" : function_id;    //"&functionid=" + functionid +

    grid.setUrl("../data/jsondata.aspx?action=" + const_get_action + "&functionid=" + const_functionId + "&totalfields=" + getPar("totalfields") + "&entity=" + const_entityName + "&condition=" + encodeURI(condition) + "&order=" + const_Order + "&datagrid=true");
    grid.load();
}
/******************************************************************************************/

//停用
var fnSetStop = function () {
    if (typeof (fnCustomSetStop) != "undefined") {
        fnCustomSetStop();
        return;
    }
    fnUpdateSingleFieldAction("is_stop", 1);
}


var fnUploadFileCallBack = function (data) {
    if (typeof (fnCustomUploadCallBack) == "function") {
        fnCustomUploadCallBack(data);
        return;
    }
    alert(data);
}



//上传文件
var fnUploadFile = function () {
    if (typeof (fnCustomUploadFile) != "undefined") {
        fnCustomUploadFile();
        return;
    }
    //var row = fnGetSelectedRow();
    mini.open({
        url: "/extendpage/upload/uploadfile.aspx?entity=" + const_EditEntity + "&functionid=" + const_functionId + "&action=importdata&id=",
        title: "上传文件" + const_PageTitle, width: 450, height: 300,
        onload: function () {
            var iframe = this.getIFrameEl();
            //var data = { action: "new" };
            var data = iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
            if (action == "ok") {
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.fnGetData();
                fnUploadFileCallBack(data);
            }
        }
    });
}



//通用单字段更新数据方法
var fnUpdateSingleFieldAction = function (field, value) {
    var rows = fnGetSelectedRows();
    var id = "";
    if (rows.length > 0) {
        if (confirm("确定更新选中记录？")) {
            var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                ids.push(r[const_entityID]);
            }
            id = ids.join(',');
        }
    }
    fnUpdateSingleFieldAction2(field, value, id, "数据保存成功！");;
    //$.ajax({
    //    url: "/extendpage/action/datasave.aspx?entity=" + const_EditEntity + "&field=" + field + "&value=" + value + "&flag=1&action=singleupdate",
    //    type: "post",
    //    data: { data: id },
    //    cache: false,
    //    success: function (text) {
    //        if (text == 1) {
    //            alert("数据保存成功!")
    //            fnClose();
    //        } else {
    //            alert(text);
    //            //alert("数据保存失败!")
    //        }
    //    },
    //    error: function (jqXHR, textStatus, errorThrown) {
    //        alert(jqXHR.responseText);
    //    }
    //});
}

//
var fnUpdateSingleFieldAction2 = function (field, value, id, message) {
    $.ajax({
        url: "/extendpage/action/datasave.aspx?entity=" + const_EditEntity + "&field=" + field + "&value=" + value + "&flag=1&action=singleupdate",
        type: "post",
        data: { data: id },
        cache: false,
        success: function (text) {
            if (text == 1) {
                alert(message);
                fnClose();
            } else {
                alert(text);
                //alert("数据保存失败!")
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        }
    });
}

//停用数据
var fnStopRecord = function () {
    fnSetStop();
}
//add by zengtongchun 2016-12-28 刷新缓存
function fnRefreshCache(key) {
    $.ajax({
        url: "/Share/RefreshCache",
        type: "post",
        data: { cacheName: key },
        cache: false,
        success: function (text) {

        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        }
    });
}

function fnRefreshCacheList(key) {
    var cacheList = fnGetData("v_data_base_dictionary_detail", "code='sys_cache'").data;
    for (var i = 0; i < cacheList.length; i++) {
        if (key == cacheList[i].value) {
            fnRefreshCache(cacheList[i].name);
        }
    }
}

//数据删除
var fnRemove = function () {
    if (typeof (fnCustomRemove) != "undefined") {
        fnCustomRemove();
        return;
    }
    if (getPar("onlystop") == "Y") {
        //停用数据
        fnStopRecord();
        return;
    }
    var rows = fnGetSelectedRows();
    if (rows.length > 0) {
        if (confirm("确定删除选中记录？")) {
            var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                console.log(const_entityID);
                ids.push(r[const_entityID]);
            }
            var id = ids.join(',');
            //console.log(id);

            //console.log(const_EditEntity);
            grid.loading("操作中，请稍后......");
            $.ajax({
                url: "/extendpage/action/datasave.aspx?functionid=" + const_functionId + "&entity=" + const_EditEntity + "&action=delete&id=" + id,
                success: function (text) {
                    if (text == 1) {
                        alert("删除成功!");
                        // add by zengtongchun 2016-12-28 刷新缓存
                        fnRefreshCacheList(const_EditEntity);
                    }
                    grid.reload();
                },
                error: function () {
                }
            });
        }
    } else {
        alert("请选中一条记录");
    }
}

/* */
var fnAudit = function () {
    if (typeof (fnCustomAudit) != "undefined") {
        fnCustomAudit();
        return;
    }
}

//退回
var fnReturn = function () {
    if (typeof (fnCustomReturn) != "undefined") {
        fnCustomReturn();
        return;
    }
}


var fnExport = function () {
    if (typeof (fnCustomExport) != "undefined") {
        fnCustomExport();
        return;
    }
    window.open(grid.url.replace(/&datagrid=true/g, "") + "&type=3");
}

var fnExportSelectedData = function () {
    if (typeof (fnCustomExport) != "undefined") {
        fnCustomExport();
        return;
    }
    var rows = fnGetSelectedRows();
    var url = grid.url.replace(/&datagrid=true/g, "").replace(/condition/g, "condition_1") + "&type=3"

    var condition = "";
    $.each(rows, function (i, e) {

        if (condition == "") {
            condition = " id='" + e.id + "' "
        }
        else {
            condition = condition + " or id='" + e.id + "'";
        }

    })

    window.open(url + "&condition=" + condition);
}


/*-------------------------------------------------------

数据窗口编辑的保存

-------------------------------------------------------*/
var fnGridSave = function () {
    if (typeof (fnCustomGridSave) != "undefined") {
        fnCustomGridSave();
        return;
    }

    var data = grid.getChanges();
    var json = mini.encode(data);

    ///数据检查
    if (typeof (fnCustomGridDataCheck) != "undefined") {
        var msg = fnCustomGridDataCheck(data);
        if (msg != "") {
            alert(msg);
            return;
        }
    }

    grid.loading("保存中，请稍后......");
    $.ajax({
        url: "/extendpage/action/datasave.aspx?entity=" + const_EditEntity + "&action=batch&flag=1",
        data: { data: json },
        type: "post",
        success: function (text) {
            grid.reload();
            alert("批量保存成功!");
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        }
    });
}



///快速定位
function QuickSearch() {
    var goodsinfo = mini.get("search").getValue();
    var rows = grid_t.findRows(function (row) {
        var goodsid = row.GOODSID;
        var goodscode = row.GOODSCODE;
        var brand = row.BRAND;
        var goodssname = row.GOODSSNAME;

        if (goodsid.match(goodsinfo) || goodscode.match(goodsinfo) || brand.match(goodsinfo) || goodssname.match(goodsinfo))
            return true;
        return false;
    });
    grid_t.scrollIntoView(rows[0]);
    grid_t.select(rows[0], false);
}


var fnEditMaster = function () {
    if (typeof (fnCustomEditMaster) != "undefined") {
        fnCustomEditMaster();
        return;
    }
}

var fnAddMaster = function () {
    if (typeof (fnCustomAddMaster) != "undefined") {
        fnCustomAddMaster();
        return;
    }
    fnInitData();
}

function fnInitData() {
    mini.prompt("表名或视图名：", "请输入",
            function (action, value) {
                if (action == "ok") {
                    fnRunProc2("usp_init_datagrid_setting", value + "," + value);
                }
            }
   );
}

//----------数据窗口相关事件-------------------------------------/
//单击单元格
var fnCellClick = function (e) {
    //alert("");
    if (typeof (fnCustomCellClick) != "undefined") {
        fnCustomCellClick(e);
        //return;
    }
}
//单击事件
var fnRowClick = function (e) {
    if (typeof (fnCustomRowClick) != "undefined") {
        fnCustomRowClick(e);
        //return;
    }
}
//双击事件
var fnDBRowClick = function (e) {
    if (typeof (fnCustomDBRowClick) != "undefined") {
        fnCustomDBRowClick(e);
        return;
    }
    if ($("#btnEdit").length > 0) {
        $("#btnEdit").click();
    }
}


$(function () {
    if (typeof (grid) != "undefined") {
        grid.on("rowclick", fnRowClick);
        grid.on("rowdblclick", fnDBRowClick);
        grid.on("cellclick", fnCellClick);
    }
});
/************************************************************************/
function onDrawSummaryCell(e) {
    if (typeof (onCustomDrawSummaryCell) == "function") {
        onCustomDrawSummaryCell(e);
        return;
    }
    else {
        var result = e.result.totaldata;
        if (result == undefined) { //add by zengtongchun 
            return;
        }
        if (result[0].records != undefined) {
            var grid = e.sender;
            //服务端汇总计算
            if (e.field == "name") {
                var s = "<span style='color:Brown;'>"
                s += "Total=" + result[0].records + "<br/>"
                        + "</span>";
                e.cellHtml = s;
            }
            var fields = getPar("totalfields");
            var _f = fields.split(",");
            $.each(_f, function (i, f) {
                if (e.field == f) {
                    var s = "<span style='color:Brown;'>"
                    s += "最大值=" + result[0]["max_" + f] + "<br/>";
                    s += "最小值=" + result[0]["min_" + f] + "<br/>";
                    s += "平均值=" + result[0]["avg_" + f] + "<br/>";
                    s += "合计值=" + result[0]["sum_" + f] + "<br/>";
                    + "</span>";
                    e.cellHtml = s;
                }
            });

        }
    }
}

///往Grid里增加新行
var fnAddNewRow = function () {
    var newRow = {};
    grid.addRow(newRow, 0);

}


//获取URL querystring parameter
function getPar1(source, name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source)) return RegExp.$2; return "";
}

function getPar(name) {
    var _url = "http://" + document.location;
    return getPar1(_url, name);
}


$(document).ready(function () {
    $("#QueryContext").keyup(function (e) {
        var key = e.which;
        if (13 == key) {
            fnQuciklyQuery();
        }
    });
    jQuery.hotkeys.add('ctrl+e', function () {
       
        fnSetSelfDatagridConfig();
    });
}
);

//打开弹窗
var fnOpenDialog = function (url, width, height, title, fnGridLoad, fnOnload) {
    mini.open({
        url: url,
        title: title,
        width: width,
        height: height,
        onload: function () {
            if (fnOnload) {
                fnOnload();
            }
        },
        ondestroy: function (action) {
            if (fnGridLoad) {
                fnGridLoad(action);
            }
        }
    });
}

/*
*
*
*/
//_alert = window.alert;
//window.alert = function (a) {
//
//}

var fnDefaultFormat = function (e) {
    if (e.value != null && e.value.toString().trim() == "0.00") {
        return "";
    }
    else if (e.value != null && e.value.toString().trim() == "1900-01-01") {
        return "";
    } else {
        return e.value;
    }
}

var fnAddTab = function (title, url) {
    parent.addTab(title, url);
}

var fnSetSelfDatagridConfig = function () {
    mini.open({
        url: "extendpage/datagrid/datagrid_config.aspx?nodataright=true&entity=t_set_datagrid&functionid=" + const_functionId + "&condition=entity='" + const_entityName + "'",
        title: "列表设置", width: 850, height: 550,
        onload: function () {
            var iframe = this.getIFrameEl();
            //var data = { action: "new" };
            iframe.contentWindow.setData(grid.columns);
        },
        ondestroy: function (action) {
            //grid.reload();
        }
    });
}



